package com.techyuan.intellij.tomcat.setting;

import com.intellij.ide.browsers.WebBrowser;
import com.intellij.ui.ListCellRendererWrapper;
import javax.swing.JList;
import org.jetbrains.annotations.NotNull;

public class WebBrowserListCellRenderer extends ListCellRendererWrapper<WebBrowser> {
    private final String myEmptySelectionText;

    public WebBrowserListCellRenderer() {
        this("[default]");
    }

    public WebBrowserListCellRenderer(@NotNull String emptySelectionText) {
        super();
        this.myEmptySelectionText = emptySelectionText;
    }

    public void customize(JList list, WebBrowser webBrowser, int index, boolean selected, boolean hasFocus) {
        if (webBrowser == null) {
            this.setText(this.myEmptySelectionText);
        } else {
            this.setIcon(webBrowser.getIcon());
            this.setText(webBrowser.getName());
        }

    }
}
